home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWArchiv / Sources / FWObjReg.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  4.7 KB  |  157 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWObjReg.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef   FWOBJREG_H
  13. #include "FWObjReg.h"
  14. #endif
  15.  
  16. #ifndef   FWPRIDEB_H
  17. #include "FWPriDeb.h"
  18. #endif
  19.  
  20. #ifndef   FWPRIMEM_H
  21. #include "FWPriMem.h"
  22. #endif
  23.  
  24. #pragma segment FWArchiv
  25.  
  26.  
  27. //========================================================================================
  28. // CLASS FW_CObjectRegistry
  29. //========================================================================================
  30.  
  31. //----------------------------------------------------------------------------------------
  32. //    FW_CObjectRegistry::~FW_CObjectRegistry
  33. //----------------------------------------------------------------------------------------
  34.  
  35. FW_CObjectRegistry::~FW_CObjectRegistry()
  36. {
  37. }
  38.  
  39. //----------------------------------------------------------------------------------------
  40. //    FW_CObjectRegistry::FW_CObjectRegistry
  41. //----------------------------------------------------------------------------------------
  42.  
  43. FW_CObjectRegistry::FW_CObjectRegistry()
  44. {
  45. }
  46.  
  47. //========================================================================================
  48. // CLASS FW_CBasicObjectRegistry
  49. //========================================================================================
  50.  
  51. //----------------------------------------------------------------------------------------
  52. //    FW_CBasicObjectRegistry::~FW_CBasicObjectRegistry
  53. //----------------------------------------------------------------------------------------
  54.  
  55. FW_CBasicObjectRegistry::~FW_CBasicObjectRegistry(void)
  56. {
  57.     FW_PrimitiveFreeBlock(fList);
  58. }
  59.  
  60. //----------------------------------------------------------------------------------------
  61. //    FW_CBasicObjectRegistry::FW_CBasicObjectRegistry
  62. //----------------------------------------------------------------------------------------
  63.  
  64. FW_CBasicObjectRegistry::FW_CBasicObjectRegistry(void) :
  65.     fList(0),
  66.     fListLength(0),
  67.     fPhysicalListLength(0),
  68.     fNextUnusedID(1)
  69. {
  70. }
  71.  
  72. //----------------------------------------------------------------------------------------
  73. //    FW_CBasicObjectRegistry::GrowList
  74. //----------------------------------------------------------------------------------------
  75.  
  76. void FW_CBasicObjectRegistry::GrowList()
  77. {
  78.     long bytesNeeded = (fPhysicalListLength+kExpansion) * sizeof(SAssociation);
  79.     if (fList == 0)
  80.         fList = (SAssociation*) FW_PrimitiveAllocateBlock(bytesNeeded);
  81.     else
  82.         fList = (SAssociation*) FW_PrimitiveResizeBlock(fList, bytesNeeded);
  83.     
  84.     for (long i=fPhysicalListLength; i<fPhysicalListLength+kExpansion; i++)
  85.         InitAssociation(fList[i]);
  86.         
  87.     fPhysicalListLength += kExpansion;
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    FW_CBasicObjectRegistry::Register
  92. //----------------------------------------------------------------------------------------
  93.  
  94. FW_CObjectRegistry::ID FW_CBasicObjectRegistry::Register(const void *object)
  95. {
  96.     FW_ASSERT(Lookup(object) == kNotInRegistry);
  97.     if (fListLength == fPhysicalListLength)
  98.         GrowList();
  99.     long entry = fListLength++;
  100.     fList[entry].fObject = object;
  101.     while (Lookup(fNextUnusedID) != 0)
  102.         fNextUnusedID++;
  103.     fList[entry].fID = fNextUnusedID++;
  104.     return fList[entry].fID;
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    FW_CBasicObjectRegistry::Register
  109. //----------------------------------------------------------------------------------------
  110.  
  111. void FW_CBasicObjectRegistry::Register(const void *object, FW_CObjectRegistry::ID id)
  112. {
  113.     FW_ASSERT(Lookup(object) == kNotInRegistry);
  114.     if (fListLength == fPhysicalListLength)
  115.         GrowList();
  116.     long entry = fListLength++;
  117.     fList[entry].fObject = object;
  118.     fList[entry].fID = id;
  119. }
  120.  
  121. //----------------------------------------------------------------------------------------
  122. //    FW_CBasicObjectRegistry::Lookup
  123. //----------------------------------------------------------------------------------------
  124.  
  125. FW_CObjectRegistry::ID FW_CBasicObjectRegistry::Lookup(const void *object)
  126. {
  127.     FW_CObjectRegistry::ID result = kNotInRegistry;
  128.     for (long i = 0; i<fListLength; i++)
  129.     {
  130.         if (fList[i].fObject == object)
  131.         {
  132.             result = fList[i].fID;
  133.             break;
  134.         }
  135.     }
  136.     return result;
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    FW_CBasicObjectRegistry::Lookup
  141. //----------------------------------------------------------------------------------------
  142.  
  143. const void* FW_CBasicObjectRegistry::Lookup(FW_CObjectRegistry::ID id)
  144. {
  145.     const void* result = 0;
  146.     for (long i = 0; i<fListLength; i++)
  147.     {
  148.         if (fList[i].fID == id)
  149.         {
  150.             result = fList[i].fObject;
  151.             break;
  152.         }
  153.     }
  154.     return result;
  155. }
  156.  
  157.